#ifndef DATA_SOURCE_H
#define DATA_SOURCE_H

#include <Types.h>
#include <AddressSpace.h>
#include <asm.h>

class DataSource{
	AddressSpace	*as;
	addr_t	offset;
	addr_t	len;
	public:
		DataSource(AddressSpace *aspace){
			as = aspace;
			offset = 0;
		}
		
		Frame * getFrame(){
			return as->getFrame(0);
		}
		
		uint32 read(char *buf, size_t sz, int32 off = -1){
			if(off >= 0) offset = off;
			uint32 frmidx = offset / FRM_SIZE;
			uint32 frm_nr = sz / FRM_SIZE;
			uint32 i, cur_sz;
			char *from_buf, *to_buf = buf;
			Frame *frm;
			kprintf("FRM_NR: %i\n", frm_nr);
			for(i = 0; i <= frm_nr; i++){
				kprintf("i: %i\n", i);
				frm = as->getFrame(frmidx);
				kprintf("FRM[%i]: %X\n", i, frm);
				from_buf = (char *)_va(_frm_to_addr(frm));
				if(sz > FRM_SIZE) cur_sz = FRM_SIZE;
				else cur_sz = sz;
				memcpy(from_buf, to_buf, cur_sz);
				to_buf += cur_sz;
				++frmidx;
				if(cur_sz < sz) sz -= cur_sz;
			}
		}
};



#endif /* DATA_SOURCE_H */
